﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chaos.messages
{
    public class process_chat_text : message
    {
        String text;
        public String Text
        {
            get { return text; }
            set { text = value; }
        }

        String user;
        public String User
        {
            get { return user; }
            set { user = value; }
        }

        public override void process(context in_context)
        {
            view.manager m = System.Windows.Application.Current.FindResource("view_manager") as view.manager;
            if (m != null)
            {
                view.chat.chat c = m.Controls["chat_control"] as view.chat.chat;
                if (c != null)
                {
                    view.chat.chat.ChatMessageEvent e = new view.chat.chat.ChatMessageEvent();
                    e.Text = Text;
                    e.User = User;
                    c.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                        new view.chat.chat.OnChatMessageDelegate(c.chat_OnChatMessage), e);                  
                }
            }
        }

        public override void serialize(stream.stream in_Stream)
        {
            in_Stream.begin("process_chat_text")
                .serialize("user", ref user)
                .serialize("text", ref text)
            .end();
        }
    }
}
